package org.tailor
class LoginClientController {
    
  def scaffold = LoginClient
  
  def login = {}
  
  def authenticate = {
    def loginClient = LoginClient.findByLoginAndPassword(params.login, params.password)
    if(loginClient){
      session.loginClient = LoginClient
      flash.message = "Hello ${loginClient.name}!"
      redirect(controller:"dashboard", action:"dashboardClient")      
    }else{
      flash.message = "Sorry, ${params.login}. Please try again."
      redirect(action:"login")
    }
  }
  
  def logout = {
    flash.message = "Goodbye ${session.loginClient.name}"
    session.loginClient = null
    redirect(controller:"dashboard", action:"dashboardClient")      
  }  
}